﻿{% extends 'base.html' %}

{% block body %}

    <!--============= Banner Section Starts Here =============-->
    <div class="hero-section bg_img style-two" data-background="../static/assets/images/banner/page-header.jpg">
        <div class="container">
            <div class="cate-header cl-white">
                <h1 class="cate-title">{{ the_title }}</h1>
                <div class="cate-meta">
                    <div>
                    <a class="custom-button" href="{{ url_for('number_entry') }}" >试一试</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--============= Banner Section Ends Here =============-->

    <!--============= Category Section Starts Here =============-->
    <section class="category-section padding-bottom mt--160 pos-rel">
        <div class="container">
            <div class="category-single-wrapper">
                <div class="single-item">
                    <h2 class="title">{{ the_title }}</h2>
                </div>
                <div class="single-item">
                    <h3 class="title">学习记录</h3>
                    <p>利用python我们甚至可以写一点小小小小小的游戏！没想到吧！（想到了）</p>
					<p>在本学期的python课程学习中，我们接触了if、else和elif的条件语句。通过使用if设立判断条件，当判断条件成立时，则实行后续代码；else 为可选语句，当需要在条件不成立时执行内容则可以执行相关语句。</p>
                    <a href="https://www.runoob.com/python/python-if-statement.html">更多python条件语句介绍</a>
                    <div class="thumb">
                        <img src="../static/assets/images/cate/ifelse.gif" alt="gif">
                    </div>
					<p>下面就让我们看看怎么通过条件语句来实现猜数字的小游戏吧！</p>
                </div>
                <div class="single-item">
                    <h3 class="title">功能介绍</h3>
                    <div class="thumb">
                        <img src="../static/assets/images/cate/guess_number.png" alt="guess_number">
                    </div>
                    <p>首先设置游戏起始参数，并利用random模块制定游戏的答案</p>
                    <pre>
                        if request.method == 'GET':
                            session['chances'] = 10 #机会次数
                            session['set_number'] = random.randint(1, 1000) #答案
                            session['number1'] = 0 #起始范围最小数
                            session['number2'] = 1000 #起始范围最大数
                            return render_template('guess_number.html')
                    </pre>
                    <p>然后</p>
                    <pre>
                        elif request.form.get('guess-number') == '': #用户输入数据
                            flash('请输入一个整数！')
                            return render_template('guess_number.html')
                        else:
                            session['chances'] -= 1 #随着输入提交次数增多，机会次数逐渐减少
                            print('要猜的数字：', session['set_number'])
                            guess_number = int(request.form.get('guess-number'))
                    </pre>
                    <p></p>
                    <pre>
                        if guess_number > session['set_number']:
                            session['number2'] = guess_number    #当输入数字大于答案数字时，最小范围数变为输入数字
                        if session.get('chances') == 0:
                            flash('Game Over！要不再玩一次？')
                            return redirect(url_for('index'))
                            flash('数字太大了，在{}~{}之中再猜一个！'.format(session['number1'], session['number2']))
                            return render_template('guess_number.html')

                        if guess_number < session['set_number']:
                            session['number1'] = guess_number
                        if session.get('chances') == 0:
                            flash('Game Over！要不再玩一次？')
                            return redirect(url_for('index'))
                            flash('数字太小了，在{}~{}之中再猜一个！'.format(session['number1'], session['number2']))
                            return render_template('guess_number.html')

                        else:
                            flash('恭喜你用了{}次机会就猜对了数字！'.format(10 - session['chances'])) #计算所用次数
                            return redirect(url_for('guess_number_entry'))
                    </pre>
                </div>
                <div class="single-item">
                    <h3 class="title">特此感谢</h3>
                    <p>该猜数字小程序源代码来自Github，可点击下方链接前往学习</p>
                    <ul class="nulla-list">
                        <li><a href="https://github.com/Yuan-Yiming/guess_the_number">原项目地址</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </section>
    <!--============= Category Section Ends Here =============-->

{% endblock %}